package com.wshl.aijiuunion.controller.activity;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.wshl.aijiuunion.GlobConstant;
import com.wshl.aijiuunion.HomeActivity;
import com.wshl.aijiuunion.R;
import com.wshl.aijiuunion.callback.RequestCallback;
import com.wshl.aijiuunion.model.RequestModel;
import com.wshl.aijiuunion.utils.BarUtils;
import com.wshl.aijiuunion.view.bean.IsShowVideoBean;

/**
 * Created buy 风凊扬 on 2019/6/25 0025
 */
public class SplashActivity extends AppCompatActivity {

    private RequestModel model;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        BarUtils.setStatusBarForActivity(this);
        model = new RequestModel();
        model.isShowVideo(this, new RequestCallback() {
            @Override
            public void onSuccess(String response) {
                IsShowVideoBean isShowVideoBean = GsonUtils.fromJson(response, IsShowVideoBean.class);
                IsShowVideoBean.DataBean data = isShowVideoBean.getData();
                int is_show = data.getIs_show();
                SPUtils.getInstance().put(GlobConstant.ISSHOWVIDEO,is_show);
                start();
            }

            @Override
            public void onError(int code) {
                start();
            }

            @Override
            public void onIntentError() {
                start();
            }
        });


    }

    private void start() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                seekto();

            }
        }, 1800);
    }


    private void seekto() {

//        String token = SPUtils.getInstance().getString(GlobConstant.TOKEN);
//        if (TextUtils.isEmpty(token)) {
//            ActivityUtils.startActivity(LoginActivity.class);
//        } else {
//            ActivityUtils.startActivity(HomeActivity.class);
//        }
//        SplashActivity.this.finish();

        ActivityUtils.startActivity(HomeActivity.class);
        SplashActivity.this.finish();
    }
}
